package com.kk.xhr.model.dao;

import static com.kk.xhr.model.dao.CandidateDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.kk.xhr.model.entity.Candidate;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface CandidateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    BasicColumn[] selectList = BasicColumn.columnList(id, recruitId, name, email, phone, gender, remark, fileId, status, created, updated);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class)
    int insert(InsertStatementProvider<Candidate> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("CandidateResult")
    Optional<Candidate> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="CandidateResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="recruit_id", property="recruitId", jdbcType=JdbcType.BIGINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="gender", property="gender", jdbcType=JdbcType.TINYINT),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="file_id", property="fileId", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="created", property="created", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updated", property="updated", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Candidate> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, candidate, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, candidate, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default int insert(Candidate record) {
        return MyBatis3Utils.insert(this::insert, record, candidate, c ->
            c.map(recruitId).toProperty("recruitId")
            .map(name).toProperty("name")
            .map(email).toProperty("email")
            .map(phone).toProperty("phone")
            .map(gender).toProperty("gender")
            .map(remark).toProperty("remark")
            .map(fileId).toProperty("fileId")
            .map(status).toProperty("status")
            .map(created).toProperty("created")
            .map(updated).toProperty("updated")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default int insertSelective(Candidate record) {
        return MyBatis3Utils.insert(this::insert, record, candidate, c ->
            c.map(recruitId).toPropertyWhenPresent("recruitId", record::getRecruitId)
            .map(name).toPropertyWhenPresent("name", record::getName)
            .map(email).toPropertyWhenPresent("email", record::getEmail)
            .map(phone).toPropertyWhenPresent("phone", record::getPhone)
            .map(gender).toPropertyWhenPresent("gender", record::getGender)
            .map(remark).toPropertyWhenPresent("remark", record::getRemark)
            .map(fileId).toPropertyWhenPresent("fileId", record::getFileId)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
            .map(created).toPropertyWhenPresent("created", record::getCreated)
            .map(updated).toPropertyWhenPresent("updated", record::getUpdated)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default Optional<Candidate> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, candidate, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default List<Candidate> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, candidate, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default List<Candidate> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, candidate, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default Optional<Candidate> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, candidate, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    static UpdateDSL<UpdateModel> updateAllColumns(Candidate record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(recruitId).equalTo(record::getRecruitId)
                .set(name).equalTo(record::getName)
                .set(email).equalTo(record::getEmail)
                .set(phone).equalTo(record::getPhone)
                .set(gender).equalTo(record::getGender)
                .set(remark).equalTo(record::getRemark)
                .set(fileId).equalTo(record::getFileId)
                .set(status).equalTo(record::getStatus)
                .set(created).equalTo(record::getCreated)
                .set(updated).equalTo(record::getUpdated);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Candidate record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(recruitId).equalToWhenPresent(record::getRecruitId)
                .set(name).equalToWhenPresent(record::getName)
                .set(email).equalToWhenPresent(record::getEmail)
                .set(phone).equalToWhenPresent(record::getPhone)
                .set(gender).equalToWhenPresent(record::getGender)
                .set(remark).equalToWhenPresent(record::getRemark)
                .set(fileId).equalToWhenPresent(record::getFileId)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(created).equalToWhenPresent(record::getCreated)
                .set(updated).equalToWhenPresent(record::getUpdated);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default int updateByPrimaryKey(Candidate record) {
        return update(c ->
            c.set(recruitId).equalTo(record::getRecruitId)
            .set(name).equalTo(record::getName)
            .set(email).equalTo(record::getEmail)
            .set(phone).equalTo(record::getPhone)
            .set(gender).equalTo(record::getGender)
            .set(remark).equalTo(record::getRemark)
            .set(fileId).equalTo(record::getFileId)
            .set(status).equalTo(record::getStatus)
            .set(created).equalTo(record::getCreated)
            .set(updated).equalTo(record::getUpdated)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: candidate")
    default int updateByPrimaryKeySelective(Candidate record) {
        return update(c ->
            c.set(recruitId).equalToWhenPresent(record::getRecruitId)
            .set(name).equalToWhenPresent(record::getName)
            .set(email).equalToWhenPresent(record::getEmail)
            .set(phone).equalToWhenPresent(record::getPhone)
            .set(gender).equalToWhenPresent(record::getGender)
            .set(remark).equalToWhenPresent(record::getRemark)
            .set(fileId).equalToWhenPresent(record::getFileId)
            .set(status).equalToWhenPresent(record::getStatus)
            .set(created).equalToWhenPresent(record::getCreated)
            .set(updated).equalToWhenPresent(record::getUpdated)
            .where(id, isEqualTo(record::getId))
        );
    }
}